package com.sdry.product.prehangingline.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sdry.common.BaseController;
import com.sdry.common.BaseTypeEnum;
import com.sdry.common.TableDataInfo;
import com.sdry.product.prehangingline.entity.PreHangingLine;
import com.sdry.product.prehangingline.entity.StationMateriel;
import com.sdry.product.prehangingline.service.PreHangingLineService;
import com.sdry.system.entity.SysUser;
import com.sdry.system.service.UserService;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: info_sdry
 * @description: 预挂线上线
 * @author: cb
 * @create: 2020-03-02 12:11
 **/
@Controller
@RequestMapping(value = "preOnLine")
public class PreOnLineController extends BaseController {

    @Autowired
    private PreHangingLineService preHangingLineService;

    @Autowired
    private UserService userService;

    /**
     * 上线
     * @return /product/preHangingLine/preOnline
     */
    @RequestMapping(value = "showPreOnLine")
    public String showPreOnLine() {
        return "/product/preHangingLine/preOnline";
    }

    /**
     * 在线
     * @return /product/preHangingLine/preZaiOnline
     */
    @RequestMapping(value = "showPreZaiOnline")
    public String showPreZaiOnline() {
        return "/product/preHangingLine/preZaiOnline";
    }

    /**
     * 下线
     * @return /product/preHangingLine/preOffline
     */
    @RequestMapping(value = "showPreOffline")
    public String showPreOffline() {
        return "/product/preHangingLine/preOffline";
    }


    /**
     * 分页查询上线/库存/下线
     * @param preHangingLine 预挂线
     * @return TableDataInfo
     */
    @RequestMapping(value = "queryPreHangingLinePage")
    @ResponseBody
    public TableDataInfo queryPreHangingLinePage(PreHangingLine preHangingLine) {
        logger.info("预挂线分页查询上线/库存/下线 preHangingLine = {} " + JSONObject.fromObject(preHangingLine));
        List<PreHangingLine> preHangingLineList = preHangingLineService.queryPreHangingLinePage(preHangingLine);
        Long total = preHangingLineService.queryPreHangingLineTotal(preHangingLine);
        return getDataTable(preHangingLineList,total);
    }

    /**
     * 分页查询库存
     * @param preHangingLine 预挂线
     * @return TableDataInfo
     */
    @RequestMapping(value = "/queryPreHangingLineStockPage")
    @ResponseBody
    public TableDataInfo queryPreHangingLineStockPage(PreHangingLine preHangingLine) {
        logger.info("预挂线分页查询上线/库存/下线 preHangingLine = {} " + JSONObject.fromObject(preHangingLine));
        List<PreHangingLine> preHangingLineList = preHangingLineService.queryPreHangingLineStockPage(preHangingLine);
        Long total = preHangingLineService.queryPreHangingLineStockTotal(preHangingLine);
        return getDataTable(preHangingLineList,total);
    }

    /**
     * 详细分页查询上线/库存/下线
     * @param stationId 预挂线
     * @return TableDataInfo
     */
    @RequestMapping(value = "queryPreHangingLineDetailPage")
    @ResponseBody
    public TableDataInfo queryPreHangingLineDetailPage(Long stationId,Long page,Long limit) {
        Map<String,Object> map = new HashMap<>(16);
        map.put("stationId",stationId);
        map.put("page",page);
        map.put("limit",limit);
        logger.info("预挂线详细分页查询上线/库存/下线 map = {} " + JSONObject.fromObject(map));
        List<StationMateriel> stationMaterielList = preHangingLineService.queryPreHangingLineDetailPage(map);
        Long total = preHangingLineService.queryPreHangingLineDetailTotal(map);
        return getDataTable(stationMaterielList,total);
    }
}
